import numpy as np
import random

def to_str(M):
    N = len(M)
    ans = ''
    ans+='{}\n'.format(N)
    for i in range(N):
        for j in range(N):
            ans+='{} '.format(M[i][j])
        ans = ans[:-1]+'\n'
    return ans

if __name__ == '__main__':
    N = 10
    L = [[0 for i in range(N)] for i in range(N)]
    U = [[0 for i in range(N)] for i in range(N)]
    for i in range(N):
        for j in range(i):
            L[i][j] = random.random()*4-2
    for i in range(N):
        L[i][i] = 1
    for i in range(N):
        for j in range(i,N):
            U[i][j] = random.random()*4-2
    print("L:")
    print(L)
    print("U:")
    print(U)
    nL = np.array(L)
    nU = np.array(U)
    nA = np.dot(nL,nU)
    print(nA[0][0])
    in_file = "dataIn.txt"
    out_file = "dataOut.txt"
    with open(in_file, 'w') as f:
        f.write(to_str(nA))
    with open(out_file, 'w') as f:
        f.write("L:\n")
        f.write(to_str(L))
        f.write("\nU:\n")
        f.write(to_str(U))